﻿namespace MyCompany.UserInterfaceLibrary {
	using System;
	using System.Windows;
	using System.Windows.Controls;
	using System.Windows.Input;

	public class CheckBoxTouch : Control {
		/// <summary>True if checked, false if not checked. This defaults to false.</summary>
		public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool), typeof(CheckBoxTouch), new FrameworkPropertyMetadata(true));

		static CheckBoxTouch() {
			DefaultStyleKeyProperty.OverrideMetadata(typeof(CheckBoxTouch), new FrameworkPropertyMetadata(typeof(CheckBoxTouch)));
		}

		/// <summary>Gets or sets the value of the <see cref="IsCheckedProperty" />. This is a dependency property.</summary>
		public bool IsChecked
		{
			get
			{
				return (bool)GetValue(IsCheckedProperty);
			}
			set
			{
				SetValue(IsCheckedProperty, value);
			}
		}

		public event EventHandler CheckRequested;

		public event EventHandler UncheckRequested;

		protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) {
			base.OnMouseLeftButtonUp(e);

			if (IsChecked) {
				if (UncheckRequested != null)
					UncheckRequested(this, new EventArgs());
			}
			else if (CheckRequested != null)
				CheckRequested(this, new EventArgs());
		}
	}
}
